From 5237255860eac6e7c9b2e06bf45763fecf582ba1 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sun, 29 Jan 2012 22:02:27 +0000 Subject: [PATCH] Code cleanup: * Group global declarations at the top * Move wfGetDB() near where it's used * Only do some stuff when really necessary --- includes/QueryPage.php | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/includes/QueryPage.php b/includes/QueryPage.php index bfdfa196ba..69912cbfa2 100644 --- a/includes/QueryPage.php +++ b/includes/QueryPage.php @@ -437,7 +437,7 @@ abstract class QueryPage extends SpecialPage { * real, honest-to-gosh query page. */ function execute( $par ) { - global $wgQueryCacheLimit; + global $wgQueryCacheLimit, $wgDisableQueryPageUpdate; $user = $this->getUser(); if ( !$this->userCanExecute( $user ) ) { @@ -445,25 +445,23 @@ abstract class QueryPage extends SpecialPage { return; } - if ( $this->limit == 0 && $this->offset == 0 ) { - list( $this->limit, $this->offset ) = $this->getRequest()->getLimitOffset(); - } - $dbr = wfGetDB( DB_SLAVE ); - $this->setHeaders(); $this->outputHeader(); $out = $this->getOutput(); - $out->setSyndicated( $this->isSyndicated() ); if ( $this->isCached() && !$this->isCacheable() ) { - $out->setSyndicated( false ); $out->addWikiMsg( 'querypage-disabled' ); return 0; } + $out->setSyndicated( $this->isSyndicated() ); + + if ( $this->limit == 0 && $this->offset == 0 ) { + list( $this->limit, $this->offset ) = $this->getRequest()->getLimitOffset(); + } + // TODO: Use doQuery() - // $res = null; if ( !$this->isCached() ) { $res = $this->reallyDoQuery( $this->limit, $this->offset ); } else { @@ -489,17 +487,15 @@ abstract class QueryPage extends SpecialPage { # If updates on this page have been disabled, let the user know # that the data set won't be refreshed for now - global $wgDisableQueryPageUpdate; if ( is_array( $wgDisableQueryPageUpdate ) && in_array( $this->getName(), $wgDisableQueryPageUpdate ) ) { $out->addWikiMsg( 'querypage-no-updates' ); } - } - } - $this->numRows = $dbr->numRows( $res ); + $this->numRows = $res->numRows(); + $dbr = wfGetDB( DB_SLAVE ); $this->preprocessResults( $dbr, $res ); $out->addHTML( Xml::openElement( 'div', array( 'class' => 'mw-spcontent' ) ) ); -- 2.20.1